var app = angular.module('myApp', []);

app.controller('myCtrl', function ($scope, $http) {
    $scope.params = {
        dt: new Date(),
        imageName: '',
        base64str: ''
    };
    $scope.result = "test";
    $scope.getFileData = function (files) {
        var file = files[0];
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function (e) {
            $scope.$apply(function () {
                $scope.params.imageName = file.name;
                $scope.params.base64str = e.target.result;
            })
        };
    }
    $scope.run = function () {
        $scope.dstImg = '';
        alert("请等待结果............");
        $scope.result = '请等待结果............';
        var params = angular.toJson($scope.params);
        // console.log("request:" + params);
        if (params != undefined) {
            $http.post("/upload/", params).then(function (response) {
                var tmp = angular.toJson(response.data, true);
                $scope.dstImg = response.data.dstImg;

                $scope.result = response.data.result;
                // $scope.$apply();//需要手动刷新
            });
        }
    }
});

var strHandler = function (strValue) {
    return strValue.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' ');
}

